home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample SMSAM / SampleSMSAM Source / TupleDatabase / CreateObject.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  3.2 KB  |  119 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CreateObject.h
  3.  
  4.     Copyright:    © 1991-1994 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Part of the AOCE Sample SMSAM Package.  Consult the license
  8.     which came with this software for your specific legal rights.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #ifndef    __CREATEOBJECT__
  15. #define    __CREATEOBJECT__
  16.  
  17. #ifndef    __TYPES__
  18. #include "Types.h"
  19. #endif
  20.  
  21. /***********************************|****************************************/
  22.  
  23. // this is the formal C++ type for our default constructor
  24. typedef void* (*Constructor) ( void* );
  25.  
  26. // this is the public interface to creating an object by string name
  27. extern void* CreateObject ( const char* className );
  28.  
  29. /*============================================================================
  30.  
  31.     TDefaultConstructorIterator is a class which allows a convenient
  32.     programmatic interface to access and iterate over the contents of a
  33.     'FcAd' resource. If the default constructor is used, the class will
  34.     attempt to load the 'FcAd' resource from the currrent application
  35.     resource fork by itself. You can also pass in an existing 'FcAd' handle.
  36.  
  37.     The following is an example of TDefaultConstructorIterator use:
  38.  
  39.     {
  40.         TDefaultConstructorIterator iterator;    // best to create object on stack
  41.         const char* const kDesiredName = "__ct__TExampleClassFv";
  42.         const char* currentName;
  43.  
  44.         for ( currentName = iterator.FirstConstructor ();
  45.               currentName != nil;
  46.               currentName = iterator.NextConstructor () )
  47.         {
  48.             if ( strcmp ( desiredName, currentName ) == 0 )
  49.                 return iterator.GetAddress ();    // we found the one we want! :)
  50.         }
  51.  
  52.         return nil;    // we did not find the one we want :(
  53.     }
  54.  
  55. ----------------------------------------------------------------------------*/
  56.  
  57. class TDefaultConstructorIterator
  58. {
  59. public:
  60.                                     TDefaultConstructorIterator ();
  61.                                     TDefaultConstructorIterator ( const Handle ctLU );
  62.                                     ~TDefaultConstructorIterator ();
  63.  
  64.     // use these to iterate over the entries
  65.  
  66.             const char*                FirstConstructor ();    // might return nil
  67.             const char*                NextConstructor ();    // will return nill when done
  68.  
  69.     // these are only valid for currrent FirstEntry or NextEntry
  70.  
  71.             const Constructor        GetConstructorAddress () const;
  72.             short                    GetConstructorResourceID () const;
  73.             unsigned long            GetConstructorOffset () const;
  74.  
  75. protected:
  76.  
  77.     static    const OSType    kCodeResourceType;
  78.     static    const OSType    kLookupResourceType;
  79.     static    const short        kLookupResourceID;
  80.  
  81. private:
  82.             Handle                    GetLookupResource ();
  83.             void                    SetupLookupResource ( Handle );
  84.  
  85.             Handle                    fResource;
  86.             SignedByte                fState;
  87.             char*                    fMaxName;
  88.             char*                    fCurrentName;
  89.             short                    fID;
  90.             unsigned long            fOffset;
  91. };
  92.  
  93. /***********************************|****************************************/
  94. /***********************************|****************************************/
  95.  
  96. #pragma push
  97. #pragma segment CreateObject
  98.  
  99. inline short
  100. TDefaultConstructorIterator::GetConstructorResourceID () const
  101. {
  102.     return fID;
  103. }
  104.  
  105. /***********************************|****************************************/
  106.  
  107. inline unsigned long
  108. TDefaultConstructorIterator::GetConstructorOffset () const
  109. {
  110.     return fOffset;
  111. }
  112.  
  113. #pragma pop
  114.  
  115. /***********************************|****************************************/
  116. /***********************************|****************************************/
  117.  
  118. #endif    // __CREATEOBJECT__
  119.